package com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.dao.TowerCraneMapper;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.model.TowerCrane;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.service.TowerCraneService;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towercrane.vo.*;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towerdata.dao.TowerDataMapper;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towerdata.model.TowerData;
import com.jxdinfo.hussar.cloud.module.example.tjjc.towernotice.dao.TowerNoticeMapper;
import com.jxdinfo.hussar.cloud.module.example.tjjc.util.DateUtil;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;
import com.jxdinfo.hussar.support.datasource.annotations.HussarDs;
import com.jxdinfo.hussar.support.mp.base.service.impl.HussarServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 塔机表服务实现类
 */
@Service("tjjc.towercrane.TowerCraneServiceImpl")
@HussarDs("master")
public class TowerCraneServiceImpl extends HussarServiceImpl<TowerCraneMapper, TowerCrane> implements TowerCraneService {

    private static final Logger logger = LoggerFactory.getLogger(TowerCraneServiceImpl.class);

    private static final String RETURN_CODE = "0";

    @Autowired
    private TowerCraneMapper towerCraneMapper;
    @Autowired
    private TowerDataMapper towerDataMapper;
    @Autowired
    private TowerNoticeMapper towerNoticeMapper;

    @Override
    public ApiResponse<List<TowerCraneVO>> findByList(TowerCraneSearchVO towerCraneSearchVO) {
        QueryWrapper<TowerCrane> wrapper = new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(towerCraneSearchVO.getId())) {
            wrapper.eq("id", towerCraneSearchVO.getId());
        }
        if(ObjectUtils.isNotEmpty(towerCraneSearchVO.getTowerName())) {
            wrapper.eq("tower_name", towerCraneSearchVO.getTowerName());
        }
        if(ObjectUtils.isNotEmpty(towerCraneSearchVO.getTyProjectCode())) {
            wrapper.eq("ty_project_code", towerCraneSearchVO.getTyProjectCode());
        }
        wrapper.eq("ty_delete_status", 0);
        List<TowerCrane> towerCranes = towerCraneMapper.selectList(wrapper);

        List<TowerCraneVO> towerCraneVOS = new ArrayList<>();
        for (TowerCrane towerCrane : towerCranes) {
            TowerCraneVO towerCraneVO = new TowerCraneVO();
            BeanUtil.copyProperties(towerCrane,towerCraneVO);
            towerCraneVOS.add(towerCraneVO);
        }

        return ApiResponse.success(towerCraneVOS);
    }

    @Override
    public ApiResponse<TowerCranePageVO> findByPage(TowerCraneSearchVO towerCraneSearchVO) {
        QueryWrapper<TowerCrane> wrapper = new QueryWrapper<>();
        Page<TowerCrane> page = new Page<>();
        page.setPages(towerCraneSearchVO.getPage());
        page.setSize(towerCraneSearchVO.getRows());

        if(ObjectUtils.isNotEmpty(towerCraneSearchVO.getId())) {
            wrapper.eq("id", towerCraneSearchVO.getId());
        }
        if(ObjectUtils.isNotEmpty(towerCraneSearchVO.getTowerName())) {
            wrapper.eq("tower_name", towerCraneSearchVO.getTowerName());
        }
        if(ObjectUtils.isNotEmpty(towerCraneSearchVO.getTyProjectCode())) {
            wrapper.eq("ty_project_code", towerCraneSearchVO.getTyProjectCode());
        }
        wrapper.eq("ty_delete_status", 0);
        wrapper.orderByDesc("ty_create_time");
        Page<TowerCrane> cranePage = towerCraneMapper.selectPage(page, wrapper);

        TowerCranePageVO towerCranePageVO = new TowerCranePageVO();
        towerCranePageVO.setData(cranePage.getRecords());
        towerCranePageVO.setCode(RETURN_CODE);
        towerCranePageVO.setCount(cranePage.getTotal());

        return ApiResponse.success(towerCranePageVO);
    }

    @Override
    public ApiResponse<List<DeviceInfoVO>> findDeviceByProductType(TowerCraneSearchVO towerCraneSearchVO) {
        //todo 没有获取设备信息service
//        List<DeviceInfoVO> list = deviceService.findDeviceByProductType(DeviceTypeEnum.DEVICE_TYPE_TOWER, towerCranePageQueryVO.getTyProjectCode());
        QueryWrapper<TowerCrane> wrapper = new QueryWrapper<>();
        wrapper.eq("ty_project_code", towerCraneSearchVO.getTyProjectCode());
        wrapper.eq("ty_delete_status",0);
        if(StrUtil.isNotEmpty(towerCraneSearchVO.getId())) {
            wrapper.ne("id", towerCraneSearchVO.getId());
        }
        List<TowerCrane> towers = towerCraneMapper.selectList(wrapper);

        Set<String> deviceCodes = new HashSet<>();
        if(towers != null) {
            deviceCodes = towers.stream().map(TowerCrane::getDeviceCode).collect(Collectors.toSet());
        }

        List<DeviceInfoVO> resultList = new ArrayList<>();

        //todo 没有获取设备信息service
//        if(list != null) {
//            for (DeviceInfoDto deviceInfoDto : list) {
//                if(!deviceCodes.contains(deviceInfoDto.getDeviceCode())) {
//                    resultList.add(deviceInfoDto);
//                }
//            }
//        }

        return ApiResponse.success(resultList);
    }

    @Override
    @Transactional
    public ApiResponse<String> add(TowerCraneVO towerCraneVO) {
        //查询塔机是否已存在
        QueryWrapper<TowerCrane> wrapper = new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(towerCraneVO.getTowerName())) {
            wrapper.eq("tower_name", towerCraneVO.getTowerName());
        }
        if(ObjectUtils.isNotEmpty(towerCraneVO.getTyProjectCode())) {
            wrapper.eq("ty_project_code", towerCraneVO.getTyProjectCode());
        }
        wrapper.eq("ty_delete_status", 0);
        TowerCrane tower = towerCraneMapper.selectOne(wrapper);
        if(ObjectUtils.isNotEmpty(tower)){
            return ApiResponse.fail("该项目下塔机名称已存在！");
        }

        QueryWrapper<TowerCrane> wrapperDevice = new QueryWrapper<>();
        wrapperDevice.eq("device_code", towerCraneVO.getDeviceCode());
        wrapperDevice.eq("ty_delete_status", 0);
        TowerCrane towerDevice = towerCraneMapper.selectOne(wrapperDevice);
        if(ObjectUtils.isNotEmpty(towerDevice)){
            return ApiResponse.fail("设备编号重复，请重新选择设备！");
        }

        TowerCrane towerCrane = new TowerCrane();
        BeanUtil.copyProperties(towerCraneVO, towerCrane);
        //todo 缺少获取用户工具类
        //towerCrane.setTyProjectCode(ContextUtil.getSessionUser().getTenantCode());
        towerCrane.setTyCreateTime(DateUtil.toLocalDateTime(new Date()));
//        towerCrane.setTyCreateUserid(ContextUtil.getUserId());
//        towerCrane.setTyCreateUserName(ContextUtil.getUserName());
        towerCrane.setTyDeleteStatus(0);
        towerCraneMapper.insert(towerCrane);

        //保存塔机实时数据
        for(int i = 1; i <= 9; i++){
            TowerData towerData = new TowerData();
            towerData.setTowerId(towerCrane.getId());
            towerData.setTowerName(towerCrane.getTowerName());
            towerData.setDataStatus(0);
            towerData.setDataType(i);
            towerData.setMeasureValue(BigDecimal.ZERO.doubleValue());
            towerData.setCollectionTime(DateUtil.toLocalDateTime(new Date()));
            towerData.setTyProjectCode(towerCrane.getTyProjectCode());
//            towerData.setTyCreateUserid(ContextUtil.getUserId()); todo
//            towerData.setTyCreateUserName(ContextUtil.getUserName()); todo
            towerData.setTyCreateTime(DateUtil.toLocalDateTime(new Date()));
            towerDataMapper.insert(towerData);
        }

        return ApiResponse.success();
    }

    @Override
    public ApiResponse<TowerCraneVO> findOne(String id) {
        TowerCrane towerCrane = towerCraneMapper.selectById(id);
        if (ObjectUtils.isNotEmpty(towerCrane)) {
            return ApiResponse.success(BeanUtil.toBean(towerCrane,TowerCraneVO.class));
        }
        return ApiResponse.fail("该塔机不存在");
    }

    @Override
    public ApiResponse<String> updateTowerCrane(TowerCraneVO towerCraneVO) {
        TowerCrane towerCraneOld = towerCraneMapper.selectById(towerCraneVO.getId());
        if (ObjectUtils.isEmpty(towerCraneOld)) {
            return ApiResponse.fail("该塔机不存在");
        }
        QueryWrapper<TowerCrane> wrapper = new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(towerCraneVO.getTowerName())) {
            wrapper.eq("tower_name", towerCraneVO.getTowerName());
        }
        if(ObjectUtils.isNotEmpty(towerCraneVO.getTyProjectCode())) {
            wrapper.eq("ty_project_code", towerCraneVO.getTyProjectCode());
        }
        wrapper.eq("ty_delete_status", 0);
        TowerCrane tower = towerCraneMapper.selectOne(wrapper);
        if(ObjectUtils.isNotEmpty(tower) && !towerCraneOld.getId().equals(tower.getId())){
            return ApiResponse.fail("该项目下塔机名称已存在");
        }
        if(towerCraneOld != null){
                /*String[] ignoreProperties = {"tyCompanyName", "tyCompanyCode", "tyProjectName", "tyProjectCode", "tyCreateTime",
                "tyCreateUserid", "tyCreateUserName", "tyLastUpdateTime", "tyLastUpdateUserid", "tyLastUpdateUserName",
                "tyDeleteStatus", "tyOpterminal", "tyRemark"};*/
            CopyOptions copyOptions = CopyOptions.create();
            copyOptions.setIgnoreNullValue(true);
            BeanUtil.copyProperties(towerCraneVO, towerCraneOld, copyOptions);
            towerCraneOld.setTyLastUpdateTime(DateUtil.toLocalDateTime(new Date()));
            //todo 缺少获取用户工具类
//            towerCraneOld.setTyLastUpdateUserid(ContextUtil.getUserId()); todo
//            towerCraneOld.setTyLastUpdateUserName(ContextUtil.getUserName()); todo
            towerCraneMapper.updateById(towerCraneOld);
        }
        return ApiResponse.success();
    }

    @Override
    public ApiResponse<String> updateNotice(TowerCraneVO towerCraneVO) {
        TowerCrane towerCraneOld = towerCraneMapper.selectById(towerCraneVO.getId());
        if(towerCraneOld != null){
            /*String[] ignoreProperties = {"tyCompanyName", "tyCompanyCode", "tyProjectName", "tyProjectCode", "tyCreateTime",
                    "tyCreateUserid", "tyCreateUserName", "tyLastUpdateTime", "tyLastUpdateUserid", "tyLastUpdateUserName",
                    "tyDeleteStatus", "tyOpterminal", "tyRemark"};*/
            CopyOptions copyOptions = CopyOptions.create();
            copyOptions.setIgnoreNullValue(true);
            BeanUtil.copyProperties(towerCraneVO, towerCraneOld, copyOptions);
            towerCraneOld.setTyLastUpdateTime(DateUtil.toLocalDateTime(new Date()));
            //todo 缺少获取用户工具类
//            towerCraneOld.setTyLastUpdateUserid(ContextUtil.getUserId()); todo
//            towerCraneOld.setTyLastUpdateUserName(ContextUtil.getUserName()); todo

            towerCraneMapper.updateById(towerCraneOld);
            return ApiResponse.success();
        }else {
            return ApiResponse.fail("该塔机不存在");
        }
    }

    @Override
    public ApiResponse<String> deleteById(TowerCraneVO towerCraneVO) {
        TowerCrane towerCraneOld = towerCraneMapper.selectById(towerCraneVO.getId());
        if(towerCraneOld != null){
            towerCraneOld.setTyDeleteStatus(1);
            towerCraneOld.setTyLastUpdateTime(DateUtil.toLocalDateTime(new Date()));
            //todo 缺少获取用户工具类
//            towerCraneOld.setTyLastUpdateUserid(ContextUtil.getUserId()); todo
//            towerCraneOld.setTyLastUpdateUserName(ContextUtil.getUserName()); todo
            towerCraneMapper.updateById(towerCraneOld);

            //删除塔机实时数据
            towerDataMapper.deleteTowerDataListByTowerId(towerCraneOld.getId());
            return ApiResponse.success();
        }else {
            return ApiResponse.fail("该塔机不存在");
        }
    }

    @Override
    public ApiResponse<Map<String, Integer>> findTowerAlarmCount(TowerCraneSearchVO towerCraneSearchVO) {
        Map<String, Integer> alarmMap = new HashMap<>();

        QueryWrapper<TowerCrane> wrapper = new QueryWrapper<>();
        wrapper.eq("ty_project_code", towerCraneSearchVO.getTyProjectCode());
        wrapper.eq("ty_delete_status", 0);
        wrapper.orderByDesc("ty_create_time");

        List<TowerCrane> towerList = new ArrayList<>();
        towerList = towerCraneMapper.selectList(wrapper);

        List<TowerDeviceInfoVO> towerOnLineDeviceList = new ArrayList<>();
        //List<TowerDeviceInfoDto> towerAllDeviceList = new ArrayList<>();

        // todo 没有获取设备信息service
//        if(ObjectUtils.isNotEmpty(towerList)){
//            Map<String, DeviceInfoVO> deviceInfoDtoMap = deviceService.findDeviceAndLocationByProductType(DeviceTypeEnum.DEVICE_TYPE_TOWER, towerCraneSearchDto.getTyProjectCode());
//            for(TowerCrane tower : towerList){
//                DeviceInfoVO towerDeviceInfoDto = deviceInfoDtoMap.get(tower.getDeviceCode());
//                if(towerDeviceInfoDto != null){
//                    if(towerDeviceInfoDto.getOnlineStatus()==1){
//                        TowerDeviceInfoVO towerDeviceInfo = new TowerDeviceInfoVO();
//                        towerDeviceInfo.setDeviceCode(towerDeviceInfoDto.getDeviceCode());
//                        towerDeviceInfo.setDeviceStatus(towerDeviceInfoDto.getOnlineStatus());
//                        towerOnLineDeviceList.add(towerDeviceInfo);
//                    }
//                }
//            }
//        }

        //获取在线设备数量
        //Integer inLineDeviceCount = dao.getTowerCount(towerCraneSearchDto.getTyProjectCode(), 0);

        //获取所有设备数量
        //Integer allDeviceCount = dao.getAllTowerCount(towerCraneSearchDto.getTyProjectCode());

        //获取预警数量
        //Integer warnCount = towerDataAlarmDao.getTowerAlarmsCount(towerCraneSearchDto.getTyProjectCode(), 1);
        Integer warnCount = towerNoticeMapper.getDayTowerNoticeCount(towerCraneSearchVO.getTyProjectCode(), 1);

        //获取报警数量
        //Integer alarmCount = towerDataAlarmDao.getTowerAlarmsCount(towerCraneSearchDto.getTyProjectCode(), 2);
        Integer alarmCount = towerNoticeMapper.getDayTowerNoticeCount(towerCraneSearchVO.getTyProjectCode(), 2);

        alarmMap.put("inLineDeviceCount",towerOnLineDeviceList.size());
        alarmMap.put("allDeviceCount",towerList.size());
        alarmMap.put("warnCount",warnCount);
        alarmMap.put("alarmCount",alarmCount);
        return ApiResponse.success(alarmMap);
    }

    @Override
    public ApiResponse<TowerTodayRealDataVO> findTowerRealData(String id, String tyProjectCode) {
        TowerTodayRealDataVO towerTodayRealDataVO = new TowerTodayRealDataVO();

        TowerCrane towerCrane = towerCraneMapper.getTowerCrane(id, tyProjectCode);

        if(ObjectUtils.isNotEmpty(towerCrane)){
            List<TowerData> towerDataList = towerDataMapper.findTowerDataList(id, tyProjectCode);
            towerTodayRealDataVO.setWorkStatus(towerCrane.getWorkStatus());
            towerTodayRealDataVO.setTodayWorkNum(towerCrane.getTodayWorkNum());
            towerTodayRealDataVO.setTodayWorkWeight(BigDecimal.valueOf(towerCrane.getTodayWorkWeight()));
            towerTodayRealDataVO.setTodayWorkDuration(towerCrane.getTodayWorkDuration());
            towerTodayRealDataVO.setTowerCockpitImg(towerCrane.getTowerCockpitImg());
            towerTodayRealDataVO.setCliverCockpitImg(towerCrane.getCliverCockpitImg());
            if(ObjectUtils.isNotEmpty(towerDataList)){
                for(TowerData towerData :towerDataList){
                    if(ObjectUtils.isNotEmpty(towerData.getDataType())){
                        if(towerData.getDataType()==1){
                            towerTodayRealDataVO.setAngle(towerData.getMeasureValue().toString());
                        }
                        if(towerData.getDataType()==2){
                            towerTodayRealDataVO.setRadius(towerData.getMeasureValue().toString());
                        }
                        if(towerData.getDataType()==3){
                            towerTodayRealDataVO.setWind(towerData.getMeasureValue().toString());
                        }
                        if(towerData.getDataType()==4){
                            towerTodayRealDataVO.setSpeed(towerData.getMeasureValue().toString());
                        }
                        if(towerData.getDataType()==5){
                            towerTodayRealDataVO.setLoadValue(towerData.getMeasureValue().toString());
                        }
                        if(towerData.getDataType()==6){
                            towerTodayRealDataVO.setHookHeight(towerData.getMeasureValue().toString());
                        }
                        if(towerData.getDataType()==7){
                            towerTodayRealDataVO.setObliquityX(towerData.getMeasureValue().toString());
                        }
                        if(towerData.getDataType()==8){
                            towerTodayRealDataVO.setObliquityY(towerData.getMeasureValue().toString());
                        }
                    }
                }
            }
        }
        return ApiResponse.success(towerTodayRealDataVO);
    }

    @Override
    public ApiResponse<List<TowerCraneVO>> findAll() {
        QueryWrapper<TowerCrane> wrapper = new QueryWrapper<>();
        wrapper.eq("ty_delete_status", 0);
        List<TowerCrane> towerCranes = towerCraneMapper.selectList(wrapper);
        List<TowerCraneVO> towerCraneVOS = new ArrayList<>();
        for (TowerCrane towerCrane : towerCranes) {
            TowerCraneVO towerCraneVO = new TowerCraneVO();
            BeanUtil.copyProperties(towerCrane,towerCraneVO);
            towerCraneVOS.add(towerCraneVO);
        }
        return ApiResponse.success(towerCraneVOS);
    }

    @Override
    public ApiResponse<AppTowerTodayRealDataVO> findMobileTowerRealData(String towerId, String tyProjectCode) {
        AppTowerTodayRealDataVO mobileTowerTodayRealDataDto = new AppTowerTodayRealDataVO();

        TowerCrane towerCrane = towerCraneMapper.getTowerCrane(towerId, tyProjectCode);

        if(ObjectUtils.isNotEmpty(towerCrane)){
            List<TowerData> towerDataList = towerDataMapper.findTowerDataList(towerId, tyProjectCode);
            mobileTowerTodayRealDataDto.setWorkStatus(towerCrane.getWorkStatus());
            mobileTowerTodayRealDataDto.setTodayWorkNum(towerCrane.getTodayWorkNum());
            mobileTowerTodayRealDataDto.setTodayWorkWeight(BigDecimal.valueOf(towerCrane.getTodayWorkWeight()));
            mobileTowerTodayRealDataDto.setTodayWorkDuration(towerCrane.getTodayWorkDuration());
            mobileTowerTodayRealDataDto.setTowerCockpitImg(towerCrane.getTowerCockpitImg());
            mobileTowerTodayRealDataDto.setCliverCockpitImg(towerCrane.getCliverCockpitImg());
            if(ObjectUtils.isNotEmpty(towerDataList)){
                for(TowerData towerData :towerDataList){
                    if(ObjectUtils.isNotEmpty(towerData.getDataType())){
                        if(towerData.getDataType()==1){
                            mobileTowerTodayRealDataDto.setAngle(towerData.getMeasureValue().toString());
                            if(towerData.getDataStatus()==0){
                                mobileTowerTodayRealDataDto.setAngleStatus("正常");
                            } else if(towerData.getDataStatus()==1){
                                mobileTowerTodayRealDataDto.setAngleStatus("预警");
                            }else if(towerData.getDataStatus()==2){
                                mobileTowerTodayRealDataDto.setAngleStatus("报警");
                            }
                            mobileTowerTodayRealDataDto.setAngleTime(DateUtil.toDate(towerData.getCollectionTime()));
                        }
                        if(towerData.getDataType()==2){
                            mobileTowerTodayRealDataDto.setRadius(towerData.getMeasureValue().toString());
                            if(towerData.getDataStatus()==0){
                                mobileTowerTodayRealDataDto.setRadiusStatus("正常");
                            } else if(towerData.getDataStatus()==1){
                                mobileTowerTodayRealDataDto.setRadiusStatus("预警");
                            }else if(towerData.getDataStatus()==2){
                                mobileTowerTodayRealDataDto.setRadiusStatus("报警");
                            }
                            mobileTowerTodayRealDataDto.setRadiusTime(DateUtil.toDate(towerData.getCollectionTime()));
                        }
                        if(towerData.getDataType()==3){
                            mobileTowerTodayRealDataDto.setWind(towerData.getMeasureValue().toString());
                            if(towerData.getDataStatus()==0){
                                mobileTowerTodayRealDataDto.setWindStatus("正常");
                            } else if(towerData.getDataStatus()==1){
                                mobileTowerTodayRealDataDto.setWindStatus("预警");
                            }else if(towerData.getDataStatus()==2){
                                mobileTowerTodayRealDataDto.setWindStatus("报警");
                            }
                            mobileTowerTodayRealDataDto.setWindTime(DateUtil.toDate(towerData.getCollectionTime()));
                        }
                        if(towerData.getDataType()==4){
                            mobileTowerTodayRealDataDto.setSpeed(towerData.getMeasureValue().toString());
                            if(towerData.getDataStatus()==0){
                                mobileTowerTodayRealDataDto.setSpeedStatus("正常");
                            } else if(towerData.getDataStatus()==1){
                                mobileTowerTodayRealDataDto.setSpeedStatus("预警");
                            }else if(towerData.getDataStatus()==2){
                                mobileTowerTodayRealDataDto.setSpeedStatus("报警");
                            }
                            mobileTowerTodayRealDataDto.setSpeedTime(DateUtil.toDate(towerData.getCollectionTime()));
                        }
                        if(towerData.getDataType()==5){
                            mobileTowerTodayRealDataDto.setLoadValue(towerData.getMeasureValue().toString());
                            if(towerData.getDataStatus()==0){
                                mobileTowerTodayRealDataDto.setLoadValueStatus("正常");
                            } else if(towerData.getDataStatus()==1){
                                mobileTowerTodayRealDataDto.setLoadValueStatus("预警");
                            }else if(towerData.getDataStatus()==2){
                                mobileTowerTodayRealDataDto.setLoadValueStatus("报警");
                            }
                            mobileTowerTodayRealDataDto.setLoadValueTime(DateUtil.toDate(towerData.getCollectionTime()));
                        }
                        if(towerData.getDataType()==6){
                            mobileTowerTodayRealDataDto.setHookHeight(towerData.getMeasureValue().toString());
                            if(towerData.getDataStatus()==0){
                                mobileTowerTodayRealDataDto.setHookHeightStatus("正常");
                            } else if(towerData.getDataStatus()==1){
                                mobileTowerTodayRealDataDto.setHookHeightStatus("预警");
                            }else if(towerData.getDataStatus()==2){
                                mobileTowerTodayRealDataDto.setHookHeightStatus("报警");
                            }
                            mobileTowerTodayRealDataDto.setHookHeightTime(DateUtil.toDate(towerData.getCollectionTime()));
                        }
                        if(towerData.getDataType()==7){
                            mobileTowerTodayRealDataDto.setObliquityX(towerData.getMeasureValue().toString());
                            if(towerData.getDataStatus()==0){
                                mobileTowerTodayRealDataDto.setObliquityXStatus("正常");
                            } else if(towerData.getDataStatus()==1){
                                mobileTowerTodayRealDataDto.setObliquityXStatus("预警");
                            }else if(towerData.getDataStatus()==2){
                                mobileTowerTodayRealDataDto.setObliquityXStatus("报警");
                            }
                            mobileTowerTodayRealDataDto.setObliquityXTime(DateUtil.toDate(towerData.getCollectionTime()));
                        }
                        if(towerData.getDataType()==8){
                            mobileTowerTodayRealDataDto.setObliquityY(towerData.getMeasureValue().toString());
                            if(towerData.getDataStatus()==0){
                                mobileTowerTodayRealDataDto.setObliquityYStatus("正常");
                            } else if(towerData.getDataStatus()==1){
                                mobileTowerTodayRealDataDto.setObliquityYStatus("预警");
                            }else if(towerData.getDataStatus()==2){
                                mobileTowerTodayRealDataDto.setObliquityYStatus("报警");
                            }
                            mobileTowerTodayRealDataDto.setObliquityYTime(DateUtil.toDate(towerData.getCollectionTime()));
                        }
                    }
                }
            }
        }
        return ApiResponse.success(mobileTowerTodayRealDataDto);
    }

    @Override
    public ApiResponse<TowerCraneVO> findTodayWorkSituation(TowerCraneSearchVO towerCraneSearchVO) {
        QueryWrapper<TowerCrane> wrapper = new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(towerCraneSearchVO.getId())){
            wrapper.eq("id", towerCraneSearchVO.getId());
        }
        wrapper.eq("ty_project_code", towerCraneSearchVO.getTyProjectCode());
        TowerCrane towerCrane = towerCraneMapper.selectOne(wrapper);
        TowerCraneVO towerCraneDto = new TowerCraneVO();
        BeanUtils.copyProperties(towerCrane, towerCraneDto);
        return ApiResponse.success(towerCraneDto);
    }
}
